<template>
	<div>
		<el-dialog :visible.sync="show" :fullscreen='false' :append-to-body="true"
			custom-class="inspect-detail-dialog taskDetail" title="巡检任务明细" :close-on-press-escape="false"
			:close-on-click-modal="false" width="80%" @open='open' :show-close="false">
			<div class="custom-dialog-cose" @click="closeDialog">
				<i class="el-icon-close"></i>
			</div>
			<div class="filter-container">
				<div class="filter-fn-input" style="margin:0 auto">
					<div class="filter-item">
						<label>设施编号</label>

						<el-input size="mini" style="width:3rem;" clearable v-model="searchParams.facilityNo"
							placeholder="请输入设施编号"></el-input>
					</div>
					<div class="filter-item">
						<label>设施类型</label>

						<el-select size="mini" v-model="searchParams.facilityName" placeholder="请选择"
							style="width: 3rem;">
							<el-option v-for="(item, index) in facilityTypeList" :key="index" :label="item.facilityName"
								:value="item.facilityName"></el-option>
						</el-select>
					</div>
					<div class="filter-item">
						<label>位置描述</label>
						<el-input size="mini" style="width: 3rem;" clearable v-model="searchParams.locationDesc"
							placeholder="请输入位置描述"></el-input>
					</div>


					<el-button type="primary" @click="getList" size="mini" style="margin-left: 0.1rem;">搜索</el-button>
					<el-button type="primary" @click="reset" size="mini">重置</el-button>
				</div>
			</div>

			<in-his-table :data="list1" :listLoading="listLoading" :tasktype="tasktype" :taskFlag="taskFlag"
				:checkedTableColumn='checkedTableColumn' :tableColumn='tableColumn' :tableChecked="tableChecked"
				@getcheckedtable="getcheckedtable" />
			<pagination v-show="page.total > 0" :total="page.total" :page.sync="page.currentPage"
				:limit.sync="page.pageSize" @pagination="getList(page)" />
		</el-dialog>
	</div>
</template>

<script>
	import Pagination from '../Pagination/index.vue';
	import task from "@/api/monitor/hiddenDanger.js";
	import inHisTable from "./inHisTable.vue";

	export default {
		name: "taskDetail",
		components: {
			Pagination,
			inHisTable,
		},
		props: {
			show: {
				required: true,
				default: false
			},
			tasktype: {
				required: true,
				default: ''
			},
			taskId: {
				required: true,
				default: ''
			},
			deptId: {
				required: true,
				default: ''
			},
		},
		data() {
			return {
				hisRadio: "巡检任务详情",
				treedata: [], //建筑树

				treeprop: {
					label: "buildingName",
					value: "id",
				},
				list1: [],
				listLoading: false,
				isMultiple: false,
				searchParams: {
					checkResult: "",
					facilityNo: "",
					facilityName: "",
					buildingAddress: "",
					facilityFloor: "",
					locationDesc: "",
					realName: "",
					phone: "",
					creatTime: "",
					planTime: "",
					taskNo: "",
				},
				page: {
					total: 0,
					currentPage: 1,
					pageSize: 10,
				},
				taskFlag: 'task',
				facilityTypeList: [], //设备类型下拉框

				// 自定义列表参数
				tableColumn: [],
				tableChecked: [],
				checkedTableColumn: [],
				defaultFormThead: [],
				checked: [],
			};
		},

		computed: {

		},
		watch: {
			show: function(val) {
				let self = this;
				if (val) {
					self.getList()
					self.getTree();
				}
			}
		},
		created() {
			this.getAllFacilityTypeList()
			this.getcheckedTableColumn()
			this.getList();
			this.getTree();
		},

		methods: {
			open() {
				this.reset()
			},
			// 列表自定义
			getcheckedtable(checked, tableKey, defaultFormThead) {
				this.checked = checked,
					this.tableKey = tableKey,
					this.defaultFormThead = defaultFormThead
				this.checkedTableColumn = defaultFormThead
			},
			getcheckedTableColumn() {
				this.tableColumn = JSON.parse(localStorage.getItem('inHisTableColumn'));
				this.tableChecked = JSON.parse(localStorage.getItem("inHisTableChecked"))
				if (this.tableColumn && this.tableChecked) {
					this.checkedTableColumn = this.tableColumn
					this.checked = this.tableChecked
				} else {
					this.checkedTableColumn = this.defaultFormThead
				}
			},
			getable(checkedTableColumn, checked, tableKey) {
				localStorage.setItem("inHisTableColumn", JSON.stringify(checkedTableColumn))
				localStorage.setItem("inHisTableChecked", JSON.stringify(checked))
				localStorage.setItem("inHisTableKey", tableKey)
				this.checkedTableColumn = JSON.parse(localStorage.getItem('inHisTableColumn'));
				this.checked = JSON.parse(localStorage.getItem("inHisTableChecked"))
				this.tableKey = localStorage.getItem("inHisTableKey")
			},
			// 设备类型LIst
			async getAllFacilityTypeList() {
				let res = await task.getAllFacilityType()

				this.facilityTypeList = res.data;

			},
			// 获取列表
			async getList() {

				this.listLoading = true;
				if (this.tasktype === 'done') {
					// 已巡检
					let res = await task.getHasTaskDetail(
						Object.assign({
								pageNum: this.page.currentPage,
								pageSize: this.page.pageSize,
								deptId: this.deptId,
								taskId: this.taskId
							},
							this.searchParams
						))

					if (res.data) {
						this.list1 = res.data.list;
						this.page.total = res.data.total;
					} else {
						this.list1 = [];
						this.page.total = 0;
					}
					this.listLoading = false;

				} else {
					let res = await task.getTaskDetail(
						Object.assign({
								pageNum: this.page.currentPage,
								pageSize: this.page.pageSize,
								deptId: this.deptId,
								taskId: this.taskId
							},
							this.searchParams
						)
					)

					if (res.data) {
						this.list1 = res.data.list;
						this.page.total = res.data.total;
					} else {
						this.list1 = [];
						this.page.total = 0;
					}
					this.listLoading = false;

				}
			},
			async getTree() {
				//获取建筑树
				let params = {};
				let res = await task.getBuildList(params)

				this.treedata = res.data;


			},

			doSearch() {
				this.isMultiple = false;
				this.getList();
			},
			searchFormHide() {
				this.isMultiple = false;
			},
			// 重置
			reset() {
				this.searchParams = {
					checkResult: "",
					facilityNo: "",
					facilityName: "",
					buildingAddress: "",
					facilityFloor: "",
					locationDesc: "",
					realName: "",
					phone: "",
					creatTime: "",
					planTime: "",
					taskNo: "",
				};
				this.page.currentPage = 1;
				this.getList();
			},
			// 导出
			exportList() {

			},
			closeDialog() {
				this.$emit("update:show", false);
			},
		},
	};
</script>

<style lang="scss">

</style>